<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/mytaglib.tld" prefix="mytag" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<fmt:setBundle basename="ua.races.raceBundle"/>
<html>
<body>
<c:set var="logoutText"><fmt:message key="logout"/></c:set>
<mytag:logout text="${logoutText}"/>

<jsp:useBean id="client" type="ua.races.vo.Client" scope="session"/>

<c:set var="helloText"><fmt:message key="client.hello"/></c:set>
<H2 align="center">${helloText} ${client.firstName} ${client.lastName}!</H2>

<c:set var="recommendText"><fmt:message key="client.future.races"/></c:set>
<h3 align="center">${recommendText}</h3>

<jsp:useBean id="races" type="java.util.List" scope="request"/>
<table align="center" summary="" border="1" bgcolor="#fff0f5">
    <thead bgcolor="#faebd7">
    <tr>
        <th>Date</th>
        <th>Time</th>
        <th>Stadium</th>
        <th>Info</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach var="race" items="${races}">
        <form action="addNewBet.do" method="POST">
            <tr>
                <td><input type="hidden" name="raceId" value="${race.raceId}"><c:out value="${race.raceDate}"/></td>
                <td><c:out value="${race.startTime}"/></td>
                <td><c:out value="${race.stadium}"/></td>
                <td><input type="submit" value="bet it!"/></td>
            </tr>
        </form>
    </c:forEach>
    </tbody>
</table>

<c:set var="prevResultsText"><fmt:message key="client.previous.results"/></c:set>
<h3 align="center">${prevResultsText}</h3>

<jsp:useBean id="fullBets" type="java.util.List" scope="request"/>

<table align="center" summary="" border="1" bgcolor="#fff0f5">
    <thead bgcolor="#faebd7">
    <tr>
        <th>Bet Date</th>
        <th>Race Date</th>
        <th>Stadium</th>
        <th>Bet Type</th>
        <th>First horse</th>
        <th>Second horse</th>
        <th>Third horse</th>
        <th>Value</th>
        <th>Result</th>
    </tr>
    </thead>
    <tbody>
    <c:choose>
        <%--<c:when test="<%=fullBets != null%>">--%>
        <c:when test="${fullBets != null}">
            <c:forEach var="fullBet" items="${fullBets}">
                <form action="viewHorsesFromRace.do">
                    <tr>
                        <td><c:out value="${fullBet.bet.betDate}"/></td>
                        <td><c:out value="${fullBet.race.raceDate}"/></td>
                        <td><c:out value="${fullBet.race.stadium}"/></td>
                        <td><c:out value="${fullBet.betType.betType}"/></td>
                        <td><c:out value="${fullBet.firstHorse.horseName}"/></td>
                        <td><c:out value="${fullBet.secondHorse.horseName}"/></td>
                        <td><c:out value="${fullBet.thirdHorse.horseName}"/></td>
                        <td><c:out value="${fullBet.bet.betValue}"/></td>
                        <td><c:out value="${fullBet.bet.result}"/></td>

                    </tr>
                </form>
            </c:forEach>
        </c:when>
        <c:otherwise>
            <h3 align="center">You don't have previous bets</h3>
        </c:otherwise>
    </c:choose>
    </tbody>
</table>


</body>
</html>